import axios from '@/libs/api.request'
import config from '@/config'

const baseUrl_lab = process.env.NODE_ENV === 'development' ? config.baseUrl.dev_lab : config.baseUrl.pro_lab

export const login = ({ userName, password }) => {
  const data = {
    userName,
    password
  }
  return axios.request({
    url: '/index/weblogin/login',
    data,
    method: 'post'
  })
}

export const getUserInfo = (token) => {
  return axios.request({
    url: '/index/weblogin/queryinfobytoken',
    params: {
      token
    },
    method: 'get'
  })
}
export const searchUserInfo = (id) => {
  return axios.request({
    url: '/index/webuser/searchUserInfo',
    params: {
      id
    },
    method: 'post'
  })
}

export const logout = (token) => {
  return axios.request({
    url: '/index/weblogin/loginout',
    method: 'post',
    params: {
      token
    }
  })
}

export const getUnreadCount = () => {
  return axios.request({
    url: 'message/count',
    method: 'get'
  })
}

export const getMessage = () => {
  return axios.request({
    url: 'message/init',
    method: 'get'
  })
}

export const getContentByMsgId = msg_id => {
  return axios.request({
    url: 'message/content',
    method: 'get',
    params: {
      msg_id
    }
  })
}

export const hasRead = msg_id => {
  return axios.request({
    url: 'message/has_read',
    method: 'post',
    data: {
      msg_id
    }
  })
}

export const removeReaded = msg_id => {
  return axios.request({
    url: 'message/remove_readed',
    method: 'post',
    data: {
      msg_id
    }
  })
}

export const restoreTrash = msg_id => {
  return axios.request({
    url: 'message/restore',
    method: 'post',
    data: {
      msg_id
    }
  })
}
// webuser

// 添加编辑
export const editwebuser = formdata => {
  return axios.request({
    url: '/index/webuser/editwebuser',
    method: 'post',
    data: formdata
  })
}

// 列表
export const listwebuser = searchdata => {
  return axios.request({
    url: '/index/webuser/getalllist',
    method: 'post',
    data: searchdata
  })
}

// 用户可用状态修改
export const updatewebuseractive = ({ id, isactive }) => {
  const data = {
    id,
    isactive
  }
  return axios.request({
    url: '/index/webuser/updateisactive',
    method: 'post',
    data: data
  })
}

// 改用户密码
export const changewebuserpasswd = formdata => {
  return axios.request({
    url: '/index/webuser/updatepasswd',
    method: 'post',
    data: formdata
  })
}

// 获取用户组列表 用于用户组列表
export const getwebusergrouplist = () => {
  return axios.request({
    url: '/index/role/getlisttree',
    method: 'post'
  })
}

// 获取用户组列表 用于用户设置
// is_active =1
export const getwebusergrouplist2 = () => {
  return axios.request({
    url: '/index/role/getlisttree',
    method: 'post',
    data: { is_active: 1 }
  })
}

// 获取顶层用户组 用于用户组设置
export const getgroupname = () => {
  return axios.request({
    url: '/index/role/getlistgroupname',
    method: 'post'
  })
}

// 保存用户组
export const saverole = (formdata) => {
  return axios.request({
    url: '/index/role/newinfo',
    method: 'post',
    data: formdata
  })
}

// 修改用户组
export const updaterole = (formdata) => {
  return axios.request({
    url: '/index/role/updateinfo',
    method: 'post',
    data: formdata
  })
}

// 保存用户组和用户关系
export const saveuserrole = (formdata) => {
  return axios.request({
    url: '/index/webuser/saveuserrole',
    method: 'post',
    data: formdata
  })
}

// 根据条件获取会员列表
export const getuserlist = (formdata) => {
  return axios.request({
    url: '/index/userinfo/getuserlist',
    method: 'post',
    data: formdata
  })
}

// 改isactive用户
export const updateuserisright = formData => {
  return axios.request({
    url: '/index/userinfo/updateuserisright',
    method: 'post',
    data: formData
  })
}

// 批量新增数据
export const batchinsertuser = ({ fileName }) => {
  return axios.request({
    url: baseUrl_lab + '/index/worker/createinfobyexcel',
    method: 'post',
    data: { fileName }
  })
}

// 获取企业列表
export const getlistbywhere = searchData => {
  return axios.request({
    url: '/index/company/getlistbywhereforadmin',
    method: 'post',
    data: searchData
  })
}
// 改企业审核
export const updateispassbyid = ({ idlist, ispass, wuid, node }) => {
  return axios.request({
    url: '/index/company/updateispassbyidforadmin',
    method: 'post',
    data: { idlist, ispass, wuid, node }
  })
}
// 改企业可用
export const updateisactivebyid = ({ id, isactive, wuid }) => {
  return axios.request({
    url: '/index/company/updateisactivebyidforadmin',
    method: 'post',
    data: { id, isactive, wuid }
  })
}
// 获取企业详情
export const getinfobyid = ({ id }) => {
  return axios.request({
    url: '/index/company/getinfobyidforadmin',
    method: 'post',
    data: { id }
  })
}
// 改企业信息
export const updateinfo = formData => {
  return axios.request({
    url: '/index/company/updateinfoforadmin',
    method: 'post',
    data: formData
  })
}
// 获取后台用户行为日志
export const getlogs = searchData => {
  return axios.request({
    url: '/index/webuser/getlogs',
    method: 'post',
    data: searchData
  })
}
